Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.pvzChannelWx = undefined;
var $2pvzChannelWeb = require("pvzChannelWeb");
var $2kc = require("kc");
var $2KDefine = require("KDefine");
var $2pvzHtBoxView = require("pvzHtBoxView");
var $2BundleManager = require("BundleManager");
var $2pvzChannel = require("pvzChannel");
exports.pvzChannelWx = /* */function (_n$pvzChannelWeb6) {
  babel_inherits(_class19, _n$pvzChannelWeb6);
  var _super121 = babel_createSuper(_class19);
  function _class19() {
    var _this286;
    babel_classCallCheck(this, _class19);
    _this286 = _super121.apply(this, arguments);
    _this286.channel = "wx";
    _this286.paraMap = new Map([["bannerAd", "adunit-4d062fdd21d3d966"], ["insertAd", "adunit-e4f183ada8b77450"], ["videoAd", "adunit-ac88badfb6986b3a"], ["nativeIcon", "adunit-b3efcc2b2236a9bd"], ["nativeBanner", "adunit-dc8cd2d29ced7c03"], ["nativeArr1", "adunit-8e9492b3ddb37e4c"], ["nativeArr2", "adunit-24580843416f9540"], ["gird9", "adunit-c01177b0dbfc2c2d"], ["gid", "6437d627ece27854d5766b47"], ["bid", "6437d661ece27854d5766b96"], ["ctrlId", "64afa242dc53360eb6884ff9"]]);
    _this286.ruanzhu = "\n著作权人:南京天豆互动网络科技有限公司  软著登记号:2022SR1082725";
    _this286.channelObj = window.wx;
    _this286.htBox = null;
    _this286.cachedBannerSize = null;
    _this286.videoFns = {
      onLoad() {
        $2kc.default.log("激励视频 广告加载成功");
      },
      onError(e) {
        $2kc.default.err(e);
        _this286.videoParas.failCall();
        _this286.channelObj.showToast({
          title: "暂无广告"
        });
        cc.game.resume();
        _this286.videoParas.endCall();
      },
      onClose(e) {
        if (e && e.isEnded) {
          try {
            _this286.videoParas.sucCall();
          } catch (t) {
            console.error(t);
          }
        }
        cc.game.resume();
        _this286.videoParas.endCall();
      }
    };
    _this286.videoParas = {
      sucCall() {},
      failCall() {},
      endCall() {}
    };
    return _this286;
  }
  babel_createClass(_class19, [{
    key: "init",
    value: function init() {
      var _this287 = this;
      babel_get(babel_getPrototypeOf(_class19.prototype), "init", this).call(this);
      var e = this.channelObj;
      if (!e) {
        return;
      }
      e.onShow(function () {
        cc.game.resume();
        if (_this287.isShare) {
          if (_this287.isShareSuc()) {
            _this287.shareSucBack && _this287.shareSucBack(), e.showToast({
              title: "分享成功!"
            });
          } else {
            e.showToast({
              title: "分享失败"
            }), _this287.shareFailBack && _this287.shareFailBack();
          }
          _this287.isShare = false;
        }
      });
      e.onHide(function () {
        cc.game.pause();
        _this287.isShare && (_this287.shareTime = new Date().getTime());
      });
      var t = this.getPara("ctrlId");
      if (t) {
        var _e149 = $2kc.default.getData("sid", null);
        if (!_e149) {
          _e149 = this.channelObj.getLaunchOptionsSync().scene;
          $2kc.default.saveData("sid", _e149);
        }
        var _a72 = {
          id: t,
          sid: _e149
        };
        $2kc.default.log("====> sid:", _e149);
        $2kc.default.jpost("https://ga.gametdd.com/adCtrl/agd/conf", _a72, function (e, t) {
          if (e) {
            $2kc.default.err(e);
          } else if ("" + t.code == "0") {
            _this287.ctrl = t.data;
            $2kc.default.log("返回", _this287.ctrl);
            _this287.onCtrlDone();
          } else {
            $2kc.default.err("返回值错误:" + JSON.stringify(t));
          }
        });
      }
      e.showShareMenu({
        withShareTicket: true,
        menus: ["shareAppMessage", "shareTimeline"]
      });
      e.onShareAppMessage(function () {
        return {};
      });
      var a = this;
      a.cacheBanner();
      setInterval(function () {
        a.cacheBanner();
      }, 5e3);
      this.getPara("gid") && $2kc.default.htInit(this.getPara("gid"));
    }
  }, {
    key: "getSysInfo",
    value: function getSysInfo() {
      this.sysInfo || (this.sysInfo = this.channelObj.getSystemInfoSync());
      return this.sysInfo;
    }
  }, {
    key: "onCtrlDone",
    value: function onCtrlDone() {
      if (this.getCtrl("p7")) {
        $2pvzChannel.pvzChannel.bt2_firstFree = true;
        $2pvzChannel.pvzChannel.bt3_firstFree = true;
        $2pvzChannel.pvzChannel.bt4_firstFree = true;
        $2kc.default.log("p7-done");
      }
    }
  }, {
    key: "getPrivacyShort",
    value: function getPrivacyShort() {
      return "";
    }
  }, {
    key: "getPrivacy",
    value: function getPrivacy() {
      return "";
    }
  }, {
    key: "canShare",
    value: function canShare() {
      return true;
    }
  }, {
    key: "shareAppMessage",
    value: function shareAppMessage(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
      var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
      if (this.canShare()) {
        this.channelObj.shareAppMessage({});
        this.shareFailBack = a;
        this.shareSucBack = t;
        this.isShare = true;
      }
    }
  }, {
    key: "copyToClip",
    value: function copyToClip(e, t) {
      this.channelObj.setClipboardData({
        data: e,
        success(e) {
          t();
        },
        fail() {
          t("复制失败");
        }
      });
    }
  }, {
    key: "showMoreGameBox",
    value: function showMoreGameBox(e, t, a) {
      if (this.htBox && this.htBox.node) {
        return void (a ? this.htBox.show(e) : this.htBox.node.active = false);
      }
      $2kc.default.log("showMoreGameBox", a);
      var n = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "ad/htBoxView", cc.Prefab));
      n.parent = e;
      n.setPosition(t);
      this.htBox = n.getComponent($2pvzHtBoxView.default);
      this.htBox.init();
      if (a) {
        this.htBox.show(e);
      } else {
        this.htBox.node.active = false;
      }
    }
  }, {
    key: "canMoreGame",
    value: function canMoreGame() {
      return true;
    }
  }, {
    key: "jumpTo",
    value: function jumpTo(e, t, a, n) {
      $2kc.default.log("jumpTo:" + e);
      this.channelObj.navigateToMiniProgram({
        appId: e,
        success: t,
        fail: a,
        complete: n
      });
    }
  }, {
    key: "cacheBanner",
    value: function cacheBanner() {
      var _this288 = this;
      var e = this.getPara("bannerAd");
      if (!e) {
        return;
      }
      if (this.bannerAd && this.cachedBannerSize) {
        return;
      }
      $2kc.default.log("cacheBanner开始", e, this.cachedBannerSize, "ad:", this.bannerAd);
      var t = window.wx;
      var a = {
        adUnitId: e,
        adIntervals: 30,
        style: {
          left: 1 - this.getSysInfo().windowWidth,
          top: this.getSysInfo().windowHeight - 1
        }
      };
      this.bannerAd = t.createBannerAd(a);
      this.bannerAd.onError(function (e) {
        $2kc.default.log("cachedBanner加载失败" + JSON.stringify(e));
        _this288.bannerAd = null;
        _this288.cachedBannerSize = null;
      });
      this.bannerAd.onResize(function (e) {
        console.log("cachedBanner onResize===", e.height, e.width);
        _this288.cachedBannerSize = e;
      });
      this.bannerAd.show().then(function () {
        $2kc.default.log("cachedBanner成功");
      }).catch(function (e) {
        $2kc.default.log("cachedBanner err:" + JSON.stringify(e));
        _this288.bannerAd = null;
        _this288.cachedBannerSize = null;
      });
    }
  }, {
    key: "showBanner",
    value: function showBanner(e, t, a) {
      var _this289 = this;
      var n = this.getPara("bannerAd");
      if (!n) {
        return;
      }
      $2kc.default.log("showBanner isShow", n, a);
      if (this.bannerAd && this.cachedBannerSize) {
        var _e150 = t ? t(this.cachedBannerSize) : {
          top: this.getSysInfo().windowHeight - this.cachedBannerSize.height,
          left: (this.getSysInfo().windowWidth - this.cachedBannerSize.width) / 2
        };
        this.bannerAd.style.top = _e150.top;
        this.bannerAd.style.left = _e150.left;
        _e150.height && (this.bannerAd.style.height = _e150.height);
        return void $2kc.default.log("cachedBanner style:", this.bannerAd.style.top, this.bannerAd.style.left, this.bannerAd.style.height);
      }
      var s = this.channelObj;
      var o = {
        adUnitId: n,
        adIntervals: 30,
        style: {
          left: 0,
          top: this.getSysInfo().windowHeight - 1
        }
      };
      this.bannerAd = s.createBannerAd(o);
      this.bannerAd.onError(function (e) {
        $2kc.default.log("banner广告加载失败" + JSON.stringify(e));
      });
      this.bannerAd.onResize(function (e) {
        console.log("banner onResize===", e.height, e.width);
        var a = t ? t(e) : {
          top: _this289.getSysInfo().windowHeight - e.height,
          left: (_this289.getSysInfo().windowWidth - e.width) / 2
        };
        _this289.bannerAd.style.top = a.top;
        _this289.bannerAd.style.left = a.left;
        a.height && (_this289.bannerAd.style.height = a.height);
        $2kc.default.log("bannerAd style:", _this289.bannerAd.style.top, _this289.bannerAd.style.left, _this289.bannerAd.style.height);
      });
      this.bannerAd.show().then(function () {
        $2kc.default.log("banner显示成功");
      }).catch(function (e) {
        _this289.bannerAd = null;
        $2kc.default.log("showBanner err:" + JSON.stringify(e));
      });
    }
  }, {
    key: "closeBanner",
    value: function closeBanner() {
      if (this.bannerAd) {
        if (this.cachedBannerSize) {
          var _e151 = {
            left: 1 - this.getSysInfo().windowWidth,
            top: this.getSysInfo().windowHeight - 1
          };
          this.bannerAd.style.left = _e151.left;
          this.bannerAd.style.top = _e151.top;
        } else {
          this.bannerAd.hide();
        }
      }
    }
  }, {
    key: "showVideo",
    value: function showVideo(e) {
      var t = this.getPara("videoAd");
      if (!t) {
        $2kc.default.log("无videoId,按成功执行");
        e.sucCall();
        return void e.endCall();
      }
      this.videoParas = e;
      cc.game.pause();
      this.rewardedVideoAd = this.channelObj.createRewardedVideoAd({
        adUnitId: t
      });
      var a = this;
      this.rewardedVideoAd.offLoad(a.videoFns.onLoad);
      this.rewardedVideoAd.offLoad();
      this.rewardedVideoAd.offError(a.videoFns.onError);
      this.rewardedVideoAd.offError();
      this.rewardedVideoAd.offClose(a.videoFns.onClose);
      this.rewardedVideoAd.offClose();
      a.rewardedVideoAd.onLoad(a.videoFns.onLoad);
      a.rewardedVideoAd.onError(a.videoFns.onError);
      a.rewardedVideoAd.onClose(a.videoFns.onClose);
      a.rewardedVideoAd.load().then(function () {
        return a.rewardedVideoAd.show();
      });
    }
  }, {
    key: "showInter",
    value: function showInter(e) {
      var t = this.getPara("insertAd");
      if (!t) {
        return;
      }
      var a = this.channelObj;
      $2kc.default.log("showInter", t);
      this.interstitialAd = a.createInterstitialAd({
        adUnitId: t
      });
      this.interstitialAd.onError(function (e) {
        console.log("插屏广告加载失败" + JSON.stringify(e));
        $2kc.default.sendMsg($2KDefine.Msg.adInterErr);
      });
      this.interstitialAd.show().then(function () {
        $2kc.default.log("插屏广告展示完成");
      }).catch(function (e) {
        $2kc.default.log("插屏广告展示失败" + JSON.stringify(e));
        $2kc.default.sendMsg($2KDefine.Msg.adInterErr);
      });
    }
  }, {
    key: "showGird9",
    value: function showGird9() {
      var e = this.channelObj;
      var t = this.getPara("gird9");
      if (!t) {
        return;
      }
      $2kc.default.log("showGird9-wx");
      if (this.boxPortalAd && this.boxPortalAd.isShow()) {
        return;
      }
      var a = {
        adUnitId: t,
        adIntervals: 30,
        style: {
          top: this.getSysInfo().windowHeight / 2 - 190,
          left: this.getSysInfo().windowWidth / 2 - 250,
          width: 500
        }
      };
      $2kc.default.log("显示gird9", a.style.top);
      this.boxPortalAd = e.createCustomAd(a);
      this.boxPortalAd.offError();
      this.boxPortalAd.onError(function (e) {
        $2kc.default.sendMsg($2KDefine.Msg.adInterErr);
        $2kc.default.log("custom广告加载失败" + JSON.stringify(e));
      });
      this.boxPortalAd.show().then(function () {
        $2kc.default.log("custom广告展示完成");
      }).catch(function (e) {
        $2kc.default.sendMsg($2KDefine.Msg.adInterErr);
        $2kc.default.log("custom广告展示失败" + JSON.stringify(e));
      });
    }
  }, {
    key: "closeGird9",
    value: function closeGird9() {
      this.boxPortalAd && this.boxPortalAd.hide();
    }
  }, {
    key: "canAutoGird9",
    value: function canAutoGird9() {
      return false;
    }
  }, {
    key: "showNative",
    value: function showNative(e, t, a, n, s) {
      var _this290 = this;
      $2kc.default.log("showCustomAd-wx", a);
      var o = this.channelObj;
      var l = this.getPara(a);
      if (!l) {
        return;
      }
      if (this.nativeAds[a]) {
        if (this.nativeAds[a].isShow()) {
          return void $2kc.default.log("原生正在显示中，不再重复显示");
        }
        this.nativeAds[a].hide();
      }
      var r = this.getSysInfo().windowHeight;
      var c = this.getSysInfo().windowWidth;
      $2kc.default.log("showCustomAd-wx", a, l, r, c);
      var d = {
        adUnitId: l,
        adIntervals: 30,
        style: {
          top: 5,
          left: c / 2 + 150
        }
      };
      if ("nativeBanner" === a) {
        d.style = {
          top: r - 90,
          left: c / 2 - 150
        };
      } else if ("nativeArr1" === a) {
        d.style = {
          top: 30,
          left: 30
        };
      } else if ("nativeArr2" === a) {
        d.style = {
          top: 30,
          left: c - 100
        };
      } else {
        "nativeIcon" === a && (d.style = t ? {
          top: 5,
          left: c / 2 + 150
        } : {
          top: 60,
          left: 260
        });
      }
      this.nativeAds[a] = o.createCustomAd(d);
      this.nativeAdCallMap.onError && this.nativeAds[a].offError(this.nativeAdCallMap.onError);
      this.nativeAds[a].offError();
      this.nativeAdCallMap.onError = function (e) {
        $2kc.default.log("原生模板广告加载失败" + JSON.stringify(e));
        _this290.nativeNodeMap[a] = 0;
      };
      this.nativeAds[a].onError(this.nativeAdCallMap.onError);
      this.nativeAdCallMap.onHide && this.nativeAds[a].offHide(this.nativeAdCallMap.onHide);
      this.nativeAds[a].offHide();
      this.nativeAdCallMap.onHide = function () {
        _this290.nativeNodeMap[a] = 0;
        $2kc.default.log("原生关闭", a);
      };
      this.nativeAds[a].onHide(this.nativeAdCallMap.onHide);
      this.nativeAds[a].show().then(function () {
        $2kc.default.log("原生展示完成", a);
        _this290.nativeNodeMap[a] = 1;
      }).catch(function (e) {
        $2kc.default.log("原生展示失败", a, JSON.stringify(e));
        _this290.nativeNodeMap[a] = 0;
      });
    }
  }, {
    key: "closeNative",
    value: function closeNative(e) {
      $2kc.default.log("closeNative", e);
      this.nativeAds[e] && this.nativeAds[e].hide();
    }
  }]);
  return _class19;
}($2pvzChannelWeb.pvzChannelWeb);